package cn.edu.cxcyzx.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
/**
 * 读取配置文件：public.properties
 * @author daier
 *
 */
public class PropertyPlaceholder extends PropertyPlaceholderConfigurer {
	
	private static Map<String, String> propertyMap;
	@Override
	protected void processProperties(
			ConfigurableListableBeanFactory beanFactoryToProcess,
			Properties props) throws BeansException {
		propertyMap =new HashMap<String, String>();
		for (Object key : props.keySet()) {
			String keyStr=key.toString();
			String value=props.getProperty(keyStr);
			propertyMap.put(keyStr, value);
		}
		// TODO Auto-generated method stub
		super.processProperties(beanFactoryToProcess, props);
	}
	/**
	 * 返回一个value
	 * @param key
	 * @return
	 */
	public static String getProperty(String key){
		return propertyMap.get(key);
	}
	/**
	 * 返回多个value(value之间用;分割)
	 * @param key
	 * @return
	 */
	public static String[] getProperties(String key){
		String values=propertyMap.get(key);
		String[] result=values.split(";");
		return result;
		
	}
}
